package com.monitor.util;

import java.util.Random;

public class RandUtil {
	
	private final static String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,!@#^*";
	
	//length用户要求产生字符串的长度
	 public static String getRandomString(int length){
	     
	     Random random=new Random();
	     StringBuffer sb=new StringBuffer();
	     for(int i=0;i<length;i++){
	       int number=random.nextInt(62);
	       sb.append(str.charAt(number));
	     }
	     return sb.toString();
	 }
	 
	 /** 
	     * 获取随机字符串 0-9 
	     * @param length    长度 
	     * @return 
	     */  
	    public static String getNumber(int length) {  
	        String str = "0123456789";  
	        Random random = new Random();  
	        StringBuffer sb = new StringBuffer();  
	        for (int i = 0; i < length; ++i) {  
	            sb.append(str.charAt(random.nextInt(10)));  
	        }  
	        return sb.toString();  
	    }  
	      
	    /** 
	     * 获取随机字符串 a-z 
	     * @param length    长度 
	     * @return 
	     */  
	    public static String getLowerLetter(int length) {  
	        String str = "abcdefghijklmnopqrstuvwxyz";  
	        Random random = new Random();  
	        StringBuffer sb = new StringBuffer();  
	        for (int i = 0; i < length; ++i) {  
	            sb.append(str.charAt(random.nextInt(26)));  
	        }  
	        return sb.toString();  
	    }  
	    
	    /** 
	     * 获取随机字符串 0-9,a-z,0-9 
	     * 有两遍0-9，增加数字概率 
	     * @param length    长度 
	     * @return 
	     */  
	    public static String getLowerLetterFu(int length) {  
	        String str = ",!@#^*()_";  
	        Random random = new Random();  
	        StringBuffer sb = new StringBuffer();  
	        for (int i = 0; i < length; ++i) {  
	            sb.append(str.charAt(random.nextInt(46)));  
	        }  
	        return sb.toString();  
	    }  
	      
	    /** 
	     * 获取随机密码，lLength位小写英文+nLength位数字 
	     * @param lLength   字母长度 
	     * @param nLength   数字长度 
	     * @return 
	     */  
	    public static String getPasswordSimple(int lLength, int nLength,int fuLength) {  
	        return getLowerLetter(lLength)+getNumber(nLength)+getLowerLetterFu(fuLength);  
	    }  
}
